﻿using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace ASPNETVN.PORTAL.Modules.EBOOK.Components
{
    public partial class Book
    {

        public static int IncreaseTotalViews(int bookID)
        {
            string spName = "p_EBOOK_Book_IncreaseTotalViews";
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand(spName);
            db.AddInParameter(dbCommand, "@BookID", DbType.Int32, bookID);
            return db.ExecuteNonQuery(dbCommand);
        }

        public static int IncreaseTotalDownloads(int bookID)
        {
            string spName = "p_EBOOK_Book_IncreaseTotalDownloads";
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand(spName);
            db.AddInParameter(dbCommand, "@BookID", DbType.Int32, bookID);
            return db.ExecuteNonQuery(dbCommand);
        }

        public static int IncreaseTotalComments(int bookID)
        {
            string spName = "p_EBOOK_Book_IncreaseTotalComments";
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand(spName);
            db.AddInParameter(dbCommand, "@BookID", DbType.Int32, bookID);
            return db.ExecuteNonQuery(dbCommand);
        }

        /// <summary>
        /// Get top books
        /// </summary>
        /// <param name="moduleID">Module ID</param>
        /// <param name="optionView">TopDownload | TopView | TopComment | None</param>
        /// <returns>Dataset</returns>
        public static DataSet GetTopItems(int moduleID, string optionView)
        {
            string spName = "[dbo].[p_EBOOK_Book_GetTopBooks]";
            Database db = DatabaseFactory.CreateDatabase();
            DbCommand dbCommand = db.GetStoredProcCommand(spName);
            db.AddInParameter(dbCommand, "@ModuleID", DbType.Int32, moduleID);
            db.AddInParameter(dbCommand, "@OptionView", DbType.String, optionView);

            return db.ExecuteDataSet(dbCommand);
        }
    }
}
